package com.yanlin;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class GuiceRuntimeContext {
    static GuiceClassLoader classLoader;

    static {
        try {
            classLoader = new GuiceClassLoader();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Class<?> loaderClass(String className) throws ClassNotFoundException {
        return classLoader.loadClass(className);
    }

    public static <T> T run(GuiceRuntimeContextRun<T> context) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        return context.run();
    }
}
